package com.shlh.saas.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shlh.saas.entity.ExportRecord;
import com.shlh.saas.mapper.ExportRecordMapper;
import com.shlh.saas.service.ExportRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 导出记录服务实现类
 */
@Slf4j
@Service
public class ExportRecordServiceImpl extends ServiceImpl<ExportRecordMapper, ExportRecord> implements ExportRecordService {
    
    @Override
    public boolean addExportRecord(Long userId, String fileName, String dataSource, String fileSize, Integer records, String filePath) {
        try {
            ExportRecord record = new ExportRecord();
            record.setUserId(userId);
            record.setFileName(fileName);
            record.setDataSource(dataSource);
            record.setFileSize(fileSize);
            record.setRecords(records);
            record.setFilePath(filePath);
            record.setExportDate(new Date());
            record.setCreatedAt(new Date());
            record.setUpdatedAt(new Date());
            
            return save(record);
        } catch (Exception e) {
            log.error("添加导出记录失败: " + e.getMessage(), e);
            return false;
        }
    }
    
    @Override
    public IPage<ExportRecord> getExportRecordsByUserId(Page<ExportRecord> page, Long userId) {
        return baseMapper.selectPageByUserId(page, userId);
    }
} 